package cn.sczhyt.modules.app.controller;

import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;
import cn.sczhyt.modules.app.annotation.Login;
import cn.sczhyt.modules.app.annotation.LoginUser;
import cn.sczhyt.modules.app.entity.UserEntity;
import cn.sczhyt.modules.szhy.entity.MeetingEntity;
import cn.sczhyt.modules.szhy.service.MeetingService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 会议基本信息表
 *
 * @author luoshijie
 * @email 1169414426@qq.com
 * @date 2020-09-03 10:22:11
 */
@Api(tags = "APP会议管理")
@RestController
@RequestMapping("app/meeting")
public class AppMeetingController {
    @Autowired
    private MeetingService meetingService;

    /**
     * 会议列表
     */
    @Login
    @ApiOperation("会议列表")
    @PostMapping("/list")
    public R list(@LoginUser UserEntity user,
                  @RequestParam(defaultValue = "1") Integer page,
                  @RequestParam(defaultValue = "20000") Integer limit,
                  @RequestBody(required = false) MeetingEntity meetingEntity) {
        String userId = user.getUserId();
        IPage<MeetingEntity> iPage = meetingService.appFindList(userId,page, limit, meetingEntity);
        PageUtils pages = new PageUtils(iPage);
        return R.ok().put("data", pages);
    }

    /**
     * 信息
     */
    @Login
    @ApiOperation("会议信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        MeetingEntity meeting = meetingService.getById(id);

        return R.ok().put("meeting", meeting);
    }

    /**
     * 会议基本信息保存,修改
     */
    @Login
    @ApiOperation("会议保存或修改")
    @PostMapping("/save")
    public R save(@RequestBody MeetingEntity meeting) {

        meetingService.meetingSave(meeting);

        return R.ok();
    }
    /**
     * 删除
     */
    @Login
    @ApiOperation("会议删除")
    @PostMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        meetingService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
